package main;

import java.util.ArrayList;

/**
 * This class represents a Inters
 * -------------------------------
 * 
 * - Attributes dc and ds storing the values needed to verify the dependency.
 *  
 * @author
 * @version
 */

public class Inters
{	
	private String dc;//one data element
	private ArrayList<String> ds;//one OR MORE data element the ArrayList of String
	private String nodeName;//name of node

	public Inters()
	{
		//dc = new String();
		//ds = new ArrayList();
	}

	/**
	 * The constructor of dc and ds.
	 * @param inters 
	 * @return void
	 */
	public Inters(Inters i)
	{
		dc = new String(i.getDc());
		ds = new ArrayList<String>(i.getDs());
	}
	
	public void setDc(String element)
	{
		dc = element;
	}
	
	public void setDs(ArrayList<String> a)
	{
		ds = a;
	}
	
	public void setDs(String element, int position)
	{
		ds.set(position, element);
	}
	
	public String getDc()
	{
		return dc;
	}
	
	public ArrayList<String> getDs()
	{
		return ds;
	}
	
	/**
	 * This element method (string) in the array ds and returns the position of it.
	 * @param string element
	 * @return int the position of array
	 */
	public int findPositionDs(String element)
	{
		 for (int it=0; it<ds.size(); it++)
		 {
		      if (ds.get(it).equals(element))
		    	  return it;   
		 }
		 
		 return -1;
	}
	
	/**
	 * Checks if arrays dc and ds are empty.
	 * @return true or false
	 */
	public Boolean isEmpty()
	{
		//System.out.println("checks if dc e ds is empty");
		if (dc.isEmpty() && ds.isEmpty())
		    return true;
		
		return false;
	}
	
	/**
	 * This function combine the objects inters.
	 * @param inters aux
	 * @return the arraylist of inters
	 */
	/*public ArrayList<Inters> combine (Inters aux)
	{
		System.out.println("This function combine the objects inters.");
		int troca=0;
		Inters res = new Inters();
		ArrayList<Inters> interLR = new ArrayList<Inters>();
		
		ArrayList<String> dsn = new ArrayList<String>();
		String dcn = new String();
		ArrayList<String> dsn1 = new ArrayList<String>();
		String dcn1 = new String();
		
		dsn = this.getDs();
		dcn = this.getDc();
		dsn1 = aux.getDs();
		dcn1 = aux.getDc();
		
		for (int i=0;i<aux.getDs().size();i++)
		{
			if (this.getDs().get(i).equals("#") && !aux.getDs().get(i).equals("#"))
			{
				dsn.set(i,(String) aux.getDs().get(i));
				troca++;
			}
			else if (!this.getDs().get(i).equals("#") && aux.getDs().get(i).equals("#"))
			{
				dsn1.set(i,this.getDs().get(i));
				troca++;
		    }
		}	
		
		if (!aux.getDc().equals("#") && this.getDc().equals("#"))
		{ 
		     dcn = aux.getDc(); troca++;
		}
		else if (aux.getDc().equals("#") && !this.getDc().equals("#"))
		{ 
			dcn1 = this.getDc(); troca++;
		}
		
		if (troca>0)
		{		
			System.out.println("VALORES DSN,DCN:"+dsn.toString()+dcn);
			System.out.println("VALORES DSN1,DCN1:"+dsn1.toString()+dcn1);
			
			if (dsn.equals(dsn1) && dcn.equals(dcn1) )
			{
				System.out.println("sao iguais, soh um entra");
				res.nodeName=this.nodeName;	
				res.setDc(dcn);
				res.setDs(dsn);
				interLR.add(res);
			} 
			else
			{
				System.out.println("sao diferentes, entram as duas");
				res.nodeName=this.nodeName;	
			    res.setDc(dcn);
			    res.setDs(dsn);
			    interLR.add(res);
				
				Inters resAux = new Inters();
				resAux.nodeName=aux.nodeName;
				resAux.setDs(dsn1);
				resAux.setDc(dcn1);
				interLR.add(resAux);
			}
		}  
					
		return interLR;
	}
	*/   //Fun��o substituida pela funcao join na classe syntATT 
	
	/**
	 * This function return String of dc and ds.
	 * @return string
	 */
	public String toString()
	{
		String str = new String();
		str = ds.toString();
		str += dc.toString();
	    
		return str;
	}
	
}
